package com.xydtech.ecard.merchant.controller;

import com.xydtech.common.annotation.Log;
import com.xydtech.common.core.controller.BaseController;
import com.xydtech.common.core.domain.AjaxResult;
import com.xydtech.common.core.domain.entity.SysDept;
import com.xydtech.common.core.domain.entity.SysDictData;
import com.xydtech.common.core.page.TableDataInfo;
import com.xydtech.common.enums.BusinessType;
import com.xydtech.common.utils.ShiroUtils;
import com.xydtech.common.utils.poi.ExcelUtilMap;
import com.xydtech.ecard.merchant.domain.EcardBranchMerchantPrd;
import com.xydtech.ecard.merchant.service.IEcardBranchMerchantPrdService;
import com.xydtech.system.mapper.SysDictDataMapper;
import com.xydtech.system.service.ISysDeptService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.LinkedHashMap;
import java.util.List;

/**
 * 网点营销个人产品信息查询
 *
 * @author yuzhiguo
 * @date 2024-09-13 上午9:15
 */
@Controller
@RequestMapping("/merchant/branchPerPrd")
public class EcardBranchPersonPrdController extends BaseController {
    @Autowired
    private IEcardBranchMerchantPrdService ecardBranchMerchantPrdService;

    @Autowired
    private SysDictDataMapper sysDictDataMapper;

    @Autowired
    private ISysDeptService sysDeptService;

    private String prefix = "merchant";

    @RequiresPermissions("merchant:branchPerPrd:view")
    @GetMapping()
    public String merchant()
    {
        return prefix + "/branchPersonPrd";
    }

    @RequiresPermissions("merchant:branchPerPrd:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(EcardBranchMerchantPrd ecardBranchMerchantPrd) {
        SysDept sysDept = sysDeptService.selectSecondLevelDeptByDeptId(ShiroUtils.getSysUser().getDeptId());
        List<SysDictData> sysDictDataList = sysDictDataMapper.selectDictDataByType("ecard_person_business_tag", sysDept.getDeptId());
        startPage();
        List<LinkedHashMap<String, Object>> list = ecardBranchMerchantPrdService.selectBranchPersonPrdInfo(ecardBranchMerchantPrd, sysDictDataList);
        return getDataTable(list);
    }

    /**
     * 获取指定类型的字典数据
     * @param dictType
     * @return
     */
    @RequiresPermissions("merchant:branchPerPrd:list")
    @PostMapping("/getPersonPrdDict")
    @ResponseBody
    public AjaxResult getEnterprisePrdDict(String dictType) {
        SysDept sysDept = sysDeptService.selectSecondLevelDeptByDeptId(ShiroUtils.getSysUser().getDeptId());
        List<SysDictData> sysDictDataList = sysDictDataMapper.selectDictDataByType("ecard_person_business_tag", sysDept.getDeptId());
        return AjaxResult.success(sysDictDataList);
    }

    @RequiresPermissions("merchant:branchPerPrd:export")
    @Log(title = "导出网点营销个人产品信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(EcardBranchMerchantPrd ecardBranchMerchantPrd)
    {
        SysDept sysDept = sysDeptService.selectSecondLevelDeptByDeptId(ShiroUtils.getSysUser().getDeptId());
        List<SysDictData> sysDictDataList = sysDictDataMapper.selectDictDataByType("ecard_person_business_tag", sysDept.getDeptId());
        List<LinkedHashMap<String, Object>> list = ecardBranchMerchantPrdService.selectBranchPersonPrdInfo(ecardBranchMerchantPrd, sysDictDataList);
        return ExcelUtilMap.getInstance().createExcel(list, "网点营销个人产品信息", "网点营销个人产品信息");
    }
}
